package com.huawei.appmarket.framework.widget;

import android.content.Context;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import o.Logger;
import o.epv;
import o.eva;

public class FoldingTextView extends TextView {
    private b ʻ;
    private c ʼ;
    protected boolean ʽ = true;
    protected float ˊ;
    protected float ˋ;
    protected String ˎ;
    protected String ˏ;
    protected int ॱ = 3;
    protected boolean ॱॱ = false;
    private String ᐝ = "...";

    public enum b {
        Init,
        All,
        Folding
    }

    public interface c {
        void ˎ(boolean z, b bVar, String str, String str2);
    }

    public FoldingTextView(Context context) {
        super(context);
        ˊ();
    }

    public FoldingTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˊ();
    }

    public FoldingTextView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˊ();
    }

    private void ˊ() {
        this.ˊ = (float) epv.ˋ(getContext(), 24);
        this.ˋ = this.ˊ;
    }

    public void setResize(boolean z) {
        this.ʽ = z;
    }

    public void setForceFolding(boolean z) {
        this.ॱॱ = z;
    }

    public void setMaxLine(int i) {
        this.ॱ = i;
    }

    public void setContent(String str) {
        this.ʻ = b.All;
        this.ˏ = null;
        this.ˎ = str;
        setText(this.ˎ);
    }

    public void setContent(String str, String str2, b bVar) {
        this.ˎ = str;
        this.ˏ = str2;
        this.ʻ = bVar;
        if (bVar != b.Folding || str2 == null) {
            this.ʻ = b.All;
            setText(str);
            return;
        }
        setText(str2);
    }

    public void setEllipsis(String str) {
        this.ᐝ = str;
    }

    public void setOnContentChangedListener(c cVar) {
        this.ʼ = cVar;
    }

    public void ˎ() {
        if (this.ˏ != null || this.ʼ == null) {
            if (this.ʻ == b.All) {
                this.ʻ = b.Folding;
                setText(this.ˏ);
            } else {
                this.ʻ = b.All;
                setText(this.ˎ);
            }
            if (this.ʼ != null) {
                this.ʼ.ˎ(true, this.ʻ, this.ˎ, this.ˏ);
                return;
            }
            return;
        }
        this.ʼ.ˎ(false, b.All, this.ˎ, this.ˏ);
    }

    protected void onMeasure(int i, int i2) {
        try {
            super.onMeasure(i, i2);
            if (this.ˏ == null && this.ʽ) {
                ˏ();
                if (this.ˏ != null) {
                    super.onMeasure(i, i2);
                }
            }
        } catch (Throwable e) {
            Logger.ˋ("FoldingTextView", "onMeasure error", e);
        }
    }

    private void ˏ() {
        int lineCount = getLineCount();
        if (lineCount != 0 || TextUtils.isEmpty(this.ˎ)) {
            int measuredWidth = getMeasuredWidth();
            if (measuredWidth > 0) {
                String str = null;
                if (lineCount > this.ॱ || (this.ॱॱ && lineCount == this.ॱ)) {
                    str = ˏ(lineCount, (measuredWidth - getPaddingLeft()) - getPaddingRight());
                } else if (this.ॱॱ && lineCount < this.ॱ) {
                    str = this.ˎ + "\r\n" + "...";
                }
                this.ˏ = str;
                ˎ();
            }
        }
    }

    private String ˏ(int i, int i2) {
        TextPaint textPaint = new TextPaint();
        textPaint.setTextSize(getTextSize());
        if (this.ᐝ == null) {
            return eva.ˊ(this.ॱ, this);
        }
        String str = eva.ˊ(this.ॱ - 1, this) + ˋ(eva.ˏ(this.ॱ, this, "FoldingTextView"), i2, textPaint);
        if (((float) i2) >= textPaint.measureText(eva.ˏ(i, this, "FoldingTextView")) + this.ˋ) {
            return str;
        }
        this.ˎ += "\r\n";
        return str;
    }

    private String ˋ(String str, int i, TextPaint textPaint) {
        float measureText = textPaint.measureText("...") + this.ˊ;
        if (((float) i) >= textPaint.measureText(str) + measureText) {
            return eva.ˊ(str) + "...";
        }
        int i2 = 1;
        do {
            str = str.substring(0, str.length() - i2);
            i2++;
        } while (((float) i) < textPaint.measureText(str) + measureText);
        return eva.ˊ(str) + "...";
    }
}
